#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "WaterMarkGenerator/WaterMarkGenerator.h"

#include <QGesture>
#include <QGestureEvent>
#include <QGestureRecognizer>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

protected:
    virtual bool event(QEvent* event) override {
        if (event->type() == QEvent::Gesture)
            return gestureEvent(static_cast<QGestureEvent*>(event));
        return QMainWindow::event(event);
    }

    virtual bool gestureEvent(QGestureEvent *event)
    {
//        qDebug() << "gestureEvent():" << event->gestures().size();
//        if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
//            swipeTriggered(static_cast<QSwipeGesture *>(swipe));
//        if (QGesture *pan = event->gesture(Qt::PanGesture))
//            panTriggered(static_cast<QPanGesture *>(pan));
        if (QGesture *pinch = event->gesture(Qt::PinchGesture))
            pinchTriggered(static_cast<QPinchGesture *>(pinch));
        return true;
    }

//    void panTriggered(QPanGesture *gesture);

//     void swipeTriggered(QSwipeGesture *gesture);

    void pinchTriggered(QPinchGesture *gesture);


private slots:
    void on_pb_load_clicked();

    void on_pb_save_clicked();

private:
    void _update_watermask();

    static QString _get_save_filename(const QString& ori_filename);

    WaterMarkGenerator::PosSizeDisc _get_pos_size_disc_from_ui() const;

private:
    Ui::MainWindow *ui;

    // const, 当前不支持改变位置
    const double percent_from_right = 13.50;
    const double percent_from_bottom = 5.50;

    double font_size_ = 1.57;

    WaterMarkGenerator generator_;

    QImage displaying_image_;

    QImage original_image_loaded_;
    QString loaded_filename_;
};
#endif // MAINWINDOW_H
